﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace EducationManagementSystem.Student
{
    public partial class StuInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind2();

            }
        }



        private void Bind()
        {
           
            SqlConnection conn = DB.Conn();
            conn.Open();
            string sql = "update Student set stuName='" + txtXm.Text + "',sex='" + this.DropDownList1.SelectedItem.Text + "',age='" + TextBox1.Text + "',mz='" + TextBox2.Text + "',syd='" + TextBox3.Text + "',birthTime='" + TextBox4.Text + "',rxrq='" + TextBox5.Text + "'  where stuid='" + Session["stuid"].ToString()+ "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            int a = cmd.ExecuteNonQuery();
 
            if (a > 0)
            {
                this.Page.RegisterStartupScript(" ", "<script>alert(' 修改成功 '); </script> ");

            }
            else
            {
                this.Page.RegisterStartupScript(" ", "<script>alert(' 对不起，修改失败 '); </script> ");
            }

        }


        private void Bind2()
        {
            txtID.Text = Session["stuid"].ToString();
            //vid = Session["vid"].ToString();
            SqlConnection conn = DB.Conn();
            conn.Open();
            string sql = "select b.className,stuName,sex,age,mz,syd,birthTime,rxrq from  Student a,Class b   where stuid='" + Session["stuid"].ToString()+ "' and a.classID=b .classID";
            SqlCommand cmd = new SqlCommand(sql, conn);
            //cmd.ExecuteNonQuery();
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(ds);
            TextBox6.Text = ds.Tables[0].Rows[0][0].ToString();
            txtXm.Text = ds.Tables[0].Rows[0][1].ToString();
            if (ds.Tables[0].Rows[0][2].ToString() == "男")
            {
                this.DropDownList1.SelectedIndex = 0; 
            }
            else
            {
                this.DropDownList1.SelectedIndex = 1; 
            }
            TextBox1.Text = ds.Tables[0].Rows[0][3].ToString();
            TextBox2.Text = ds.Tables[0].Rows[0][4].ToString();
            TextBox3.Text = ds.Tables[0].Rows[0][5].ToString();
            TextBox4.Text = ds.Tables[0].Rows[0][6].ToString();
            TextBox5.Text = ds.Tables[0].Rows[0][7].ToString();


        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Bind();
        }
    }
}